package com.lqk.fnandroid.navigation

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.lqk.fnandroid.R
import com.lqk.fnandroid.databinding.FragmentMainBinding

/**
 * 主入口
 */
class MainFragment : Fragment() {

    companion object {
        const val TAG = "MainFragment"
    }

    // fragment 可能销毁 造成内存泄漏
    private lateinit var binding: FragmentMainBinding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentMainBinding.inflate(layoutInflater)
        return binding.root
//        return inflater.inflate(R.layout.fragment_main, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        binding.tvToPassword.setOnClickListener {
            Log.d(TAG, "onViewCreated: Main -> Password")
            findNavController().navigate(R.id.action_mainFragment_to_loginPasswordFragment)
        }
        binding.tvToVerify.setOnClickListener {
            Log.d(TAG, "onViewCreated: Main -> Password")
            findNavController().navigate(R.id.action_mainFragment_to_loginVerifyFragment)
        }
    }
}